﻿#include "RemoveCompound.h"
// core
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
//framework
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
//python
#include "FITK_Kernel/FITKPython/FITKPythonInterface.h"
//operator
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
#include "OperatorsInterface/GraphEventOperator.h"
#include "FITK_Kernel/FITKCore/FITKActionOperator.h"
#include "OperatorsInterface/ParaWidgetInterfaceOperator.h"
//interface
#include "FITK_Interface/FITKInterfaceGeometry/FITKGeoCommandList.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKGeoInterfaceFactory.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelOperSolid.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelSphere.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoMultiDelete.h"
//component
#include "FITK_Component/FITKGeoCompOCC/FITKOCCModelSolid.h"
#include "FITK_Component/FITKGeoCompOCC/FITKOCCModelOperCompound.h"
#include <QMetaEnum>
#include <QDebug>

RemoveCompound::RemoveCompound(int id /*= 0*/)
{
    if (id == 0) return;
    m_command = wTools.getGeoCommand(Interface::FITKGeoEnum::FITKGeometryComType::FGTCompoundRemoveShape);
    if (!m_command) wTools.updateExecutionStatus(false);
    else m_RemoveCompound = dynamic_cast<Interface::FITKAbsGeoModelOperCompound*>(m_command);
}

RemoveCompound::RemoveCompound(Interface::FITKAbsGeoModelOperCompound* RemoveCompound)
{
    m_command = m_RemoveCompound = RemoveCompound;
}

const QString RemoveCompound::getClassName()
{
    return "RemoveCompound";
}

bool RemoveCompound::setInputCmdId(int cmdId)
{
    if (!m_RemoveCompound) return false;
    m_RemoveCompound->setInputCmdId(Interface::VirtualShape(cmdId, -1));
    return true;
}

bool RemoveCompound::setShapeCmdIndex(int cmdIdIndex)
{
    if (!m_RemoveCompound) return false;
    QList<Interface::VirtualShape> vShapes;
    vShapes.append(Interface::VirtualShape(m_RemoveCompound->getInputCmdId().CmdId, cmdIdIndex));
    m_RemoveCompound->setShapeCmdIds(vShapes);
    return true;
}

RemoveCompound* RemoveCompoundWrapper::new_RemoveCompound()
{
    return new RemoveCompound(-1);
}

void RemoveCompoundWrapper::delete_RemoveCompound(RemoveCompound* obj)
{
    if (obj) delete obj;
}

void RemoveCompoundWrapper::setInputCmdName(RemoveCompound* obj, const QString& name)
{
    auto data = geoCmdUndoList->getDataByName(name);
    bool flag = data;
    if (data) obj->setInputCmdId(data->getDataObjectID());
    wTools.updateExecutionStatus(flag);
}

void RemoveCompoundWrapper::setRemoveIndex(RemoveCompound * obj, int index)
{
    auto removeCommand = dynamic_cast<Interface::FITKAbsGeoModelOperCompound*>(obj->getCommand());
    bool flag = removeCommand;
    wTools.updateExecutionStatus(flag);
    if (!flag) return;
    obj->setShapeCmdIndex(index);
}

void RemoveCompoundWrapper::update(RemoveCompound* obj)
{
    auto RemoveCompound = dynamic_cast<Interface::FITKAbsGeoModelOperCompound*>(obj->getCommand());

    // 执行操作器刷新命令。
    auto m_Operator = FITKOPERREPO->getOperatorT<EventOper::ParaWidgetInterfaceOper>("actionCompoundRemoveShape");

    // 传递输入参数。
    auto vShapes = RemoveCompound->getShapeCmdIds();
    auto compoundVShape = RemoveCompound->getInputCmdId();
    m_Operator->setArgs("CompoundVShape", QVariant::fromValue(compoundVShape));
    m_Operator->setArgs("VShapes", QVariant::fromValue(vShapes));

    // 执行功能。
    bool flag = m_Operator->execProfession();
    wTools.updateExecutionStatus(flag);

    // 获取数据ID。
    int histId = -1;
    if (flag && m_Operator->argValue("Id", histId))
        registerSig(obj, histId, "delete");
}

RemoveCompound* RemoveCompoundWrapper::static_RemoveCompound_Create()
{
    return new_RemoveCompound();
}
